package com.navinfo.platform.common.utils;

import org.apache.spark.Partitioner;

/**
 * Created by neo on 2017/7/7.
 */
public class TidPartitioner extends Partitioner {

    private int partitionNum = 1000;
    public TidPartitioner(){}

    public TidPartitioner(int partitionNum){
        this.partitionNum = partitionNum;
    }

    @Override
    public int numPartitions() {
        return this.partitionNum;
    }

    @Override
    public int getPartition(Object key) {

        try {
            return (int)(Long.parseLong(key.toString()) % partitionNum);
        } catch (NumberFormatException e){
            e.printStackTrace();
        }
        return 0;
    }
}
